/*--------------------劳务模块.劳务公司管理--ly-----------------*/
/*---------------------劳务公司信息修改功能  lb_company_edit.html------------------*/


$(document).ready(function() {
	//获取cookie:ueserid & Wtid
	var companyid = $.cookie("companyid");
	var editcookie = $.cookie("nav");
	var Wtid = JSON.parse(editcookie).w;

	//填充数据
	var searchurl = laborport + '/LabourCompanyController/selectById'; //查询
	$.post(searchurl, {
		'companyid': companyid,
	}, function(result) {
		var code = result.code;
		var editlist = result.object;
		if(code == 0) {
			$("#L_name").val(editlist.name); //劳务公司
			$("#L_addr").val(editlist.addr); //地址
		} else {
			console.log("网络不佳，稍后再试！")
		}
	});

	//layui
	layui.use(['form', 'layer'], function() {
		$ = layui.jquery;
		var form = layui.form,
			layer = layui.layer;

		//自定义验证规则
		form.verify({
			username: function(value) {
				if(value.length < 3) {
					return '昵称至少得5个字符啊';
				}
			},
		});

		//获取表单数据
		$("input").blur(function() {
			//失去焦点事件
			var name = $("#L_name").val(); //劳务公司
			var addr = $("#L_addr").val(); //地址
			//监听提交
			form.on('submit(edit)', function() {
				//递交修改
				editData(name, addr,);
				return false;
			});
		});

		//修改用户信息
		var editurl = laborport + '/LabourCompanyController/update'; //修改
		// 获得frame索引
		var index = parent.layer.getFrameIndex(window.name);
		var editData = function(name, addr,) {
			//修改 edit
			$.post(editurl, {
				companyid: companyid,
				name: name,
				addr:addr
			}, function(result) {
				var code = result.code;
				if(code == 0) {
					layer.msg('修改成功!', {
						icon: 1,
						time: 1000
					}, function() {
						//关闭当前frame
						parent.layer.close(index);
					});
				} else {
					layer.msg('网络开小差了，请稍后再试!', {
						icon: 2,
						time: 1000
					}, function() {
						//关闭当前frame
//						parent.layer.close(index);
					});
				}
			})
		}

	});
})